import { Column, DeleteDateColumn, Entity, PrimaryGeneratedColumn, Index, OneToOne, JoinColumn, UpdateDateColumn, CreateDateColumn } from "typeorm";
import { Category } from "src/modules/category/entities/category.entity";
@Entity('books_tb')
@Index(['book_name'],{ unique: false })
export class Book {
    @PrimaryGeneratedColumn({ comment: '图书编号'})
    id: number;
    @Column({ name: 'book_name', default: null, comment: '图书名称'})
    book_name: string;
    @Column({ name: 'author', default: null, comment:'作者'})
    author:string;
    @Column({ name: 'postion', default: null, comment:'图书位置'})
    postion:string;
    @Column({ default: null, comment: '图书封面'})
    cover:string;
    @Column({ name: 'status', default: 0, comment:'借阅状态 0可借1已借' })
    status:number;
    @Column({ name: 'describe', type: 'text', default: null, comment:'图书简介' })
    describe:string;
    @Column({ name: 'ISBN', default: null, comment:'国际标准书号' })
    ISBN:string;
    @Column({ name: 'publisher', default: null, comment:'出版社' })
    publisher:string;
    @Column({ name: 'publish_date', default: null, comment:'出版日期' })
    publish_date:Date;
    @CreateDateColumn({ name: 'create_time', type: 'datetime', comment:'创建时间' })
    create_time:Date;
    @UpdateDateColumn({ name: 'update_time', comment:'更新时间' })
    update_time:Date;
    @Column({select: false})
    @DeleteDateColumn({ select: false, name: 'delete_time', default: null, comment:'删除时间' })
    delete_time:Date;
    // createForeignKeyConstraints不设置外键约束
    @OneToOne(() => Category, (category) => category.book, { createForeignKeyConstraints: false})
    @JoinColumn({name: 'category_id'})
    category_id: number;
}
